module.exports=class extends baseLogic{
    constructor(){
        super();
       
    }

    static init(){
        return new this();
    }

    async getItems(queryModel){
        let ret = await this.DB.iframe_config.getItems(queryModel);
        return ret;
    }

    async getItem(key){
        let ret = await this.DB.iframe_config.Access.findOne({
            where:{
                ConfigKey:key
            },
            raw:true
        });
        return ret;
    }

    async insertOrUpdate(_model){
        var OldKey =_model.OldKey;
        var model = {};
        if (OldKey && OldKey != '') {
            model = await this.DB.iframe_config.Access.findById(OldKey);
            if(!model){
                return null;
            }
            model=model.dataValues;
        } else {
            model = {};
        }
        model.ConfigKey = _model.ConfigKey;
        model.ConfigValue = _model.ConfigValue;
        model.ConfigInfo = _model.ConfigInfo;
        if (OldKey && OldKey != '') {
            model = await this.DB.iframe_config.Access.update(model, {
                where: {
                    ConfigKey: OldKey
                }
            });
        } else {
            model =  await this.DB.iframe_config.Access.create(model);
        }
        await this.func.systemConfig.Sync();
        return model;
    }

    async del(keys){
         await this.DB.iframe_config.Access.destroy({
            where: {
                ConfigKey: keys
            }
        });
         for(let key in keys){
             await this.func.systemConfig.del(key);
         }

    }
}
